import { Game } from './core/Game';

class MinecraftWeb {
  private canvas: HTMLCanvasElement;
  private game: Game;

  constructor() {
    this.canvas = document.getElementById('game-canvas') as HTMLCanvasElement;
    if (!this.canvas) {
      throw new Error('游戏画布未找到');
    }

    this.game = new Game(this.canvas);
    this.init();
  }

  private init(): void {
    this.setupCanvas();
    this.game.start();
  }

  private setupCanvas(): void {
    this.canvas.width = window.innerWidth;
    this.canvas.height = window.innerHeight;

    window.addEventListener('resize', () => {
      this.canvas.width = window.innerWidth;
      this.canvas.height = window.innerHeight;
      this.game.handleResize();
    });
  }
}

new MinecraftWeb();